package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.im.sfs.bean.chat.GreetMessage
import com.polaris.live.net.chatService
import com.polaris.live.resp.go_resp.UploadGreetBean

/**
 * MessageGreetViewModel
 *
 * @author Created by 长空 on 2023/10/21 16:35
 * @since 1.0.0
 */
class MessageGreetViewModel : BaseViewModel() {

    val greetListLiveData = MutableLiveData<ResultState<List<GreetMessage>>>()
    val uploadGreetListLiveData = MutableLiveData<Any>()
    val deleteGreetListLiveData = MutableLiveData<Any>()
    val putGreetListLiveData = MutableLiveData<Any>()

    /**
     * 获取打招呼列表
     */
    fun getGreetList() {
        request({ chatService.getGreetList() }, greetListLiveData)
    }

    /**
     * 上传打招呼列表
     */
    fun uploadGreet(uploadGreetBean: UploadGreetBean) {
        requestLoading({
            chatService.uploadGreet(uploadGreetBean)
        }, { uploadGreetListLiveData.postValue(it) }, {
            ToastGravity.showGravity(it.errorMsg)
        })
    }

    /**
     * 修改打招呼列表
     */
    fun putGreet(uploadGreetBean: UploadGreetBean) {
        requestLoading({
            chatService.putGreet(uploadGreetBean)
        }, { putGreetListLiveData.postValue(it) }, {
            ToastGravity.showGravity(it.errorMsg)
        })
    }

    /**
     * 删除打招呼列表
     */
    fun deleteGreet(greetTemplateId: Int) {
        request({
            chatService.deleteGreet(greetTemplateId)
        }, { deleteGreetListLiveData.postValue(it) }, {
            ToastGravity.showGravity(it.errorMsg)
        })
    }

}